import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    menu: [],
    loginData: {},
  },
  mutations: {
    updateMenu: (state, arr) => {
      state.menu = arr
    },
    setloginData(state, data) {
      state.loginData = data
    },
  },
  actions: {
    async getLoginData({
      commit
    }, _this) {
      const res = await _this.ax('/user/login', {
        username: _this.loginForm.username.match(/\d+/),
        password: _this.loginForm.password
      })
      console.log(res);
      if (res.code === 0) {
        const loginData = res.data
        localStorage.setItem("G:token", loginData.token)
        commit('setloginData', loginData.data)
        window.location.href = './boss.html'
      }else{
        _this.$message.error(res.message)
      }
    },
  },
})
